//
//  LiveBaseViewController.m
//  VoiceLive
//
//  Created by 凸阿滨 on 2017/10/25.
//  Copyright © 2017年 WB. All rights reserved.
//

#import "LiveBaseViewController.h"
#import "LiveHeaderView.h"
#import <AliyunOSSiOS/OSSService.h>
@interface LiveBaseViewController ()<UIImagePickerControllerDelegate,UINavigationBarDelegate>
{
    LiveHeaderView *_headerView;
    UIButton *_resetLoginBtn;
}
@property(nonatomic,strong) NSString *bucket;
@property(nonatomic,strong) OSSClient *client;
@property(nonatomic,strong) UIImagePickerController *imagePicker;;  /*照片选择控制器 */
@end

@implementation LiveBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
     self.view.backgroundColor = [UIColor whiteColor];
    
    [self initUI];
    
    
}

- (void)initUI{
    _resetLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _resetLoginBtn.backgroundColor = [UIColor blackColor];
    [_resetLoginBtn setTitle:@"退出" forState:UIControlStateNormal];
    [_resetLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _resetLoginBtn.frame = CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 50);
    [_resetLoginBtn addTarget:self action:@selector(resetAction) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:_resetLoginBtn];
    
}


#pragma mark 提示框封装
- (void)alertMessage:(NSString *)message{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVc addAction:action];
    [self presentViewController:alertVc animated:YES completion:nil];
    
}


//设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStatusBarBackgroundColor:[UIColor blackColor]];
    
}

#pragma mark 调用相机相册选择版
- (void)fetchSinglePicture{
    UIAlertController *AlertSelect = [[UIAlertController alloc]init];
    UIAlertAction *camera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:_imagePicker animated:YES completion:nil];
    }];
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentViewController:_imagePicker animated:YES completion:nil];
    }];
    UIAlertAction *photoLibrary = [UIAlertAction actionWithTitle:@"照片库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:_imagePicker animated:YES completion:nil];
    }];
    
    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [AlertSelect addAction:camera];
    [AlertSelect addAction:photo];
    [AlertSelect addAction:cancelAction];
    [AlertSelect addAction:photoLibrary];
    [self presentViewController:AlertSelect animated:YES completion:nil];
}

- (void)HUDText:(NSString *)text{
    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:_HUD];
    _HUD.label.text = text;
    _HUD.mode = MBProgressHUDModeText;
    
    [_HUD showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [_HUD removeFromSuperview];
        _HUD = nil;
    }];
    
}


@end
